using System;
using System.Web;
using System.Web.UI;
using System.Web.Core;

namespace Forum.Business
{
    public class GroupAdd : ForumUserControl
    {
        protected ValuedTextBox subjectTextBox;
        protected ValuedCheckBox enabledCheckBox;
        protected ResourceButton saveButton;

        protected override void OnLoad(EventArgs e)
        {
            if (!ValidatePermission(PermissionType.SectionAdmin))
            {
                throw new Exception("Access denied.");
            }
            saveButton.Click += new EventHandler(SaveGroup);
        }

        private void SaveGroup(object sender, EventArgs e)
        {
            Group group = new Group();

            group.Subject.Value = subjectTextBox.Value;
            group.Enabled.Value = enabledCheckBox.Checked ? (int)EnableStatus.Enable : (int)EnableStatus.Disable;

            BusinessManager.CreateGroup(group);

            Page.Response.Redirect(UrlManager.Instance.FormatUrl("group_list"));
        }
    }
}